package com.example.demo.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.entity.Meeting;
import com.example.demo.mapper.MeetingMapper;
import com.example.demo.service.MeetingService;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class MeetingServiceImpl extends ServiceImpl<MeetingMapper, Meeting> implements MeetingService {
    /**
     * 将meetingroom集合中对应的meeting找出来
     * @param ret 存储meeting的集合
     * @return 返回查到的Meeting
     */
    @Override
    public List<Meeting> getByMeetingId(List<String> ret, String userId) {
        LambdaQueryWrapper<Meeting> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(Meeting::getMeetingId,ret).ne(Meeting::getHostId,userId);
        return list(queryWrapper);
    }

    @Override
    public List<Meeting> getRencentByMeetingDate(List<String> ret) {
        LambdaQueryWrapper<Meeting> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(Meeting::getMeetingId,ret).in(Meeting::getMeetingDate, LocalDate.now());
        return list(queryWrapper);
    }

    @Override
    public List<String> getBtwTime(Meeting meeting) {
        LambdaQueryWrapper<Meeting> queryWrapper = new LambdaQueryWrapper<Meeting>()
                .between(Meeting::getMeetingStime,meeting.getMeetingStime(),meeting.getMeetingEtime())
                .between(Meeting::getMeetingEtime,meeting.getMeetingStime(),meeting.getMeetingEtime())
                .or()
                .eq(Meeting::getMeetingDate,LocalDate.now())
                .select(Meeting::getMeetingroomId);
        return list(queryWrapper).stream().map(Meeting::getMeetingroomId).collect(Collectors.toList());
    }

    @Override
    public List<Meeting> getMeetingByHost(List<String> ret,String userId) {
        LambdaQueryWrapper<Meeting> queryWrapper = new LambdaQueryWrapper<Meeting>()
                .in(Meeting::getMeetingId,ret).eq(Meeting::getHostId,userId);

        return list(queryWrapper);
    }
}
